package dao.impl;

import bean.Notice;
import dao.BaseDao;
import dao.NoticeDao;

import java.util.ArrayList;

public class NoticeDaoImpl extends BaseDao implements NoticeDao {
    @Override
    public int insert(Notice notice) {
        String sql = "INSERT INTO `t_notice` (`title`,`details`,`n_time`)VALUES(?,?,?)";
        return update(sql,notice.getTitle(),notice.getDetails(),notice.getN_time());
    }

    @Override
    public int delete(Integer id) {
        String sql = "DELETE FROM `t_notice` WHERE `n_id`=?";
        return update(sql,id);
    }

    @Override
    public int update(Notice notice) {
        String sql = "UPDATE `t_notice` SET `title`=?,`details`=?,`n_time`=? WHERE `n_id`=?";
        return update(sql,notice.getTitle(),notice.getDetails(),notice.getN_time(),notice.getN_id());
    }

    @Override
    public Notice queryById(Integer id) {
        String sql = "SELECT * FROM `t_notice` WHERE `n_id`=?";
        return queryForOne(Notice.class,sql,id);
    }

    @Override
    public ArrayList<Notice> queryAll() {
        String sql = "SELECT * FROM `t_notice`";
        return queryForList(Notice.class,sql);
    }
}
